package 算法练习;/**
 * @author： li
 * @date： 2022-01-08 12:58
 * @version 1.0
 */

/**
 * @author： ljm
 * @date： 2022-01-08 12:58
 * @version 1.0
 */
import java.util.Scanner;
public class 跳马02 {
    private static int minunm =Integer.MAX_VALUE;
    private static int[][] isOk = new int[9][9];
    private static int a,b,c,d;
    private static int[] fx= { 2, 1,-1,-2,-2,-1, 1, 2};
    private static int[] fy= {-1,-2,-2,-1, 1, 2, 2, 1};
    static boolean check(int x,int y)
    {
        return x >= 0 && y >= 0 && x <= 8 && y <= 8;
    }
    static void horseRun(int x,int y,int step)
    {
        if (step>=minunm)
            return;
        if(x==c&&y==d){
            minunm=step;
            return;
        }
        for (int i = 0; i < 8; i++) { //表示每一个格都有八种走法
            if (check((x + fx[i]), (y + fy[i]))) {
                int xx = x + fx[i];
                int yy = y + fy[i];
                if(isOk[xx][yy]==0){
                    isOk[xx][yy]=1;
                    horseRun(xx,yy,step+1);
                    isOk[xx][yy]=0;
                }
            }
        }
    }
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        a = sc.nextInt();b = sc.nextInt();
        c = sc.nextInt();d = sc.nextInt();
        for(int i=0;i<8;i++)
            for(int j=0;j<8;j++) {
                isOk[i][j]=0;
            }

        isOk[a][b]=1;
        horseRun(a,b,0);
        if(minunm==Integer.MAX_VALUE)
            System.out.println(-1);
        else
            System.out.println(minunm);
    }
}
